package com.cskaoyan.market.controller.wx;

import com.cskaoyan.market.db.domain.MarketStorage;
import com.cskaoyan.market.service.wx.CloudService;
import com.cskaoyan.market.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Author: chenjian
 * @Date: 2024/5/20 9:13
 */
@RestController
@RequestMapping("wx/storage")
public class WxStorageController {
    @Autowired
    CloudService cloudService;


    @PostMapping("upload")

    public Object upload(MultipartFile file) throws IOException {
        InputStream inputStream = null;
        try {
            inputStream = file.getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        MarketStorage marketStorage = cloudService.oss(inputStream);
        if (marketStorage != null) {
            return ResponseUtil.ok(marketStorage);
        } else return ResponseUtil.badArgument();
    }
}
